package com.example.tangjiangxu.kotlintest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by tangjiangxu on 5/31/17.
 */

public class LoginActivity2 extends Activity {
    private static final String TAG = "LoginActivity2";
    private Button bnClick;
    private EditText etName;
    private EditText etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        etName = (EditText) findViewById(R.id.et_name);
        etPassword = (EditText) findViewById(R.id.et_password);
        bnClick = (Button) findViewById(R.id.bn_login);
        bnClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                User user = new User();
                String name = etName.getText().toString().trim();
                String passage = etPassword.getText().toString().trim();
                user.setName(name);
                user.setPassword(passage);
                login(user);
            }
        });
    }

    private void login(User user) {
        if (login(user.getName(), user.getPassword())) {
            Toast.makeText(this, "登录成功！", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "失败！", Toast.LENGTH_SHORT).show();
        }
    }

    private boolean login(String name, String passwrod) {
        if ("123".equals(name) && "123".equals(passwrod)) {
            return true;
        } else {
            return false;
        }
    }
}
